clear all;clc;
rand('seed',10);
init=randn(100,1); 
num=10000; dim=length(init);

A=randn(num,dim);
b=randn(num,1);

cvx_begin;
variable sol(dim);
variable t(dim);
minimize(quad_over_lin(A * sol - b, 1) +  ones(1,dim)*t );
subject to 
    -t<= sol<=t;
cvx_end;

ssg=@(x)(gobj_lst(x,A,b));
prox=@(x,a)(prox_norm_1(x,a));
theta=0.0;
[v2,path]=ssg_prox_nag(ssg,prox,init,theta);
 sol=v2;
[dim,iter]=size(path);

for i=1:iter
    v(i)=norm(path(:,i)-sol);
end
loglog(v,'-')
grid on;
hold on;


theta=0.3;
[v2,path]=ssg_prox_nag(ssg,prox,init,theta);
% sol=v2;
[dim,iter]=size(path);

for i=1:iter
    v(i)=norm(path(:,i)-sol);
end
loglog(v,'--')
grid on;
hold on;

theta=0.6;
[v2,path]=ssg_prox_nag(ssg,prox,init,theta);
%sol=v2;
[dim,iter]=size(path);

for i=1:iter
    v(i)=norm(path(:,i)-sol);
end
loglog(v,'-.')
grid on;
hold on;

theta=0.9;
[v2,path]=ssg_prox_nag(ssg,prox,init,theta);
% sol=v2;
[dim,iter]=size(path);

for i=1:iter
    v(i)=norm(path(:,i)-sol);
end
loglog(v,':')
grid on;
hold on;
legend('\theta=0','\theta=0.3','\theta=0.6','\theta=0.9');
%%
clear all;clc;
rand('seed',10);
init=randn(100,1); 
num=10000; dim=length(init);
A=randn(num,dim);
b=randn(num,1);

cvx_begin;
variable sol(dim);
variable t(dim);
minimize(quad_over_lin(A * sol - b, 1) +  ones(1,dim)*t );
subject to 
    -t<= sol<=t;
cvx_end;

ssg=@(x)(gobj_lst(x,A,b));
prox=@(x,a)(prox_norm_1(x,a));
theta=0.0;
[v2,path]=ssg_prox_nag(ssg,prox,init,theta);
sol=v2;
[dim,iter]=size(path);

for i=1:iter
    v(i)=norm(path(:,i)-sol);
end
loglog(v,'-')
grid on;
hold on;

theta=1.0;
[v2,path]=ssg_prox_nag(ssg,prox,init,theta);
% sol=v2;
[dim,iter]=size(path);
for i=1:iter
    v(i)=norm(path(:,i)-sol);
end
loglog(v,'--')
grid on;
hold on;

l=legend('$\theta_k=0$','$\theta_k=\frac{1}{k+3}$');
set(l,'Interpreter','latex');